package com.lagou.mr.homework;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class SortBean implements WritableComparable<SortBean> {

    private int id;
    private Long num;
// 构造方法
    public SortBean() {
    }

    public SortBean(int id, Long num) {
        this.id = id;
        this.num = num;
    }

    public int getId(int i) {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Long getNum() {
        return num;
    }

    public void setNum(Long num) {
        this.num = num;
    }
//排序 从小到大
    @Override
    public int compareTo(SortBean o) {
        if(o.num > this.num) {
            return -1;
        } else if(o.num < this.num){
            return 1;
        } else {
            return 0;
        }
    }
// 序列化
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(id);
        out.writeLong(num);
    }
// 反序列化
    @Override
    public void readFields(DataInput in) throws IOException {
        this.id = in.readInt();
        this.num = in.readLong();
    }

    @Override
    public String toString() {
        return id + "\t" + num ;
    }
}
